package com.schoolvisitors.entity;

import com.schoolvisitors.enums.InstrumentLoanStatusEnum;
import com.schoolvisitors.enums.InstrumentLoanType;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
@Entity
@Table(name = "instrument_loans", schema = "school_visitors")
public class InstrumentLoan {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Size(max = 32)
    @Column(name = "instrument_name", length = 32)
    private String instrumentName;

    @Size(max = 1024)
    @Column(name = "instrument_imgs", length = 1024)
    private String instrumentImgs;

    @Size(max = 1024)
    @Column(name = "return_imgs", length = 1024)
    private String returnImgs;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "type", nullable = false, length = 16)
    private InstrumentLoanType type;

    @NotNull
    @Column(name = "reviewer_id", nullable = false)
    private Long reviewerId;

    @NotNull
    @ColumnDefault("CURRENT_TIMESTAMP")
    @Column(name = "borrow_time", nullable = false)
    private LocalDateTime borrowTime;

    @Column(name = "return_time")
    private LocalDateTime returnTime;


    @Column(name = "points")
    private Long points;

    @NotNull
    @ColumnDefault("CURRENT_TIMESTAMP")
    @Column(name = "create_at", nullable = false)
    private LocalDateTime createAt;

    @Size(max = 255)
    @NotNull
    @Column(name = "remark", nullable = false)
    private String remark;


    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 32)
    private InstrumentLoanStatusEnum status;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "instrument_id")
    private Instrument instrument;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "return_room_id")
    private Room returnRoom;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "borrow_room_id")
    private Room borrowRoom;

}